package com.xds.gulimall.order.config;


import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @author : baixu
 * @date : 17:14 2021/12/23
 */
@Configuration
public class MyRabbitConfig {
//    @Autowired
//    RabbitTemplate rabbitTemplate;
    @Bean
    public MessageConverter messageConverter(){
    return     new Jackson2JsonMessageConverter();
    }
    /**
     * 定制RabbitTemplate
     */
//    @PostConstruct
//    public void initRabbitTemplate(){
//        rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {
//            @Override
//            public void confirm(CorrelationData correlationData, boolean ack, String cause) {
//                System.out.println("confirm...correlationData["+correlationData+"]");
//            }
//        });
//        //交换机抵达队列失败回掉
//        rabbitTemplate.setReturnsCallback(new RabbitTemplate.ReturnsCallback() {
//            @Override
//            public void returnedMessage(ReturnedMessage returned) {
//                System.out.println("失败消息"+returned.getMessage());
//                System.out.println("失败路由key"+returned.getRoutingKey());
//                System.out.println("失败交换机"+returned.getExchange());
//            }
//        });
//    }

}
